import uuid
from enum import StrEnum

from pydantic import BaseModel, Field



class TurnDetectionType(StrEnum):
    ServerVAD = "server_vad"


class ClientEventType(StrEnum):
    InputAudioBufferAppend = "input_audio_buffer.append"
    SessionUpdate = "session.update"


def uuid_string():
    return str(uuid.uuid4())


class TurnDetection(BaseModel):
    type: TurnDetectionType | None = None


class Session(BaseModel):
    id: str | None = None
    turn_detection: TurnDetection | None = None


class ClientEvent(BaseModel):
    event_id: str = Field(default_factory=uuid_string)
    type: str


class InputAudioBufferAppend(ClientEvent):
    type: ClientEventType = ClientEventType.InputAudioBufferAppend
    audio: str


class SessionUpdate(ClientEvent):
    session: Session
    type: ClientEventType = ClientEventType.SessionUpdate

